package edu.gyc.hishiro.service.impl;

import edu.gyc.hishiro.model.SysUserRole;
import edu.gyc.hishiro.dao.SysUserRoleDao;
import edu.gyc.hishiro.service.SysUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ls
 * @since 2021-01-04
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleDao, SysUserRole> implements SysUserRoleService {

    @Override
    public void addRoleUser(Integer uid, Integer roleId) {
        SysUserRole userRole=this.lambdaQuery().eq(SysUserRole::getUid,uid)
                .eq(SysUserRole::getRoleId,roleId).one();
        if (userRole != null) { //该id的用户已有该角色，不需要再增加了
            return;
        }
       SysUserRole myuserrole=new SysUserRole();
        myuserrole.setRoleId(roleId);
        myuserrole.setUid(uid);
        this.save(myuserrole);
    }
}
